package com.qiyadeng.wechat.roo.model;
import java.util.List;

import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

import com.qiyadeng.wechat.config.WeChatConstant;

@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "PROD")
@RooDbManaged(automaticallyDelete = true)
public class Prod {
	
	//得到某一个目录中所有的产品
	public static List<Prod> getProdsByCatId(Integer catId){
		
		List<Prod> list = entityManager().createQuery("select o from Prod o where o.catId=?1",Prod.class)
				.setParameter(1, catId)
				.getResultList();
		return list;
	}
	
	//得到推荐n各产品
	public static List<Prod> getTopNProds(){
		List<Prod> list = entityManager().createQuery("select o from Prod o where o.status=?1",Prod.class)
				.setParameter(1, WeChatConstant.PROD_STATUS_RECOMMEND)
				.getResultList();
		return list;
	}
	
}
